<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>阳光图书馆_注册</title>
<script type="text/javascript" src="js/register_js.js"></script>
<script type="text/javascript" src="js/test_time.js"></script>

<style>
body {
	background-image: url(image/home_bg.jpg);
		background-repeat: no-repeat;
}
.my-container {
	background-color: rgba(255,255,255,1);
	height: 800px !important;
	border-radius:20px;
}
.my-nav-link {
	font-size: 24px;
	color: rgba(0,68,128,1.00);
}
</style>
<link rel="stylesheet" href="css/direction.css">

<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
<script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.bootcss.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>

<script src="js/u_r_s.js"></script>

</head>

<body>

<nav class="direct_bar">
  <div class="logo"> <a href="index.html"><img src="image/sunny.png" style="width: 235px; height: 45px" class="img_logo"></a> </div>
  <div class="page_links" style="height:50px">
    <ul class="nav justify-content-center">
      <li class="nav-item"><a href="index.html" class="nav-link">首&nbsp;&nbsp;页</a></li>
      <li class="nav-item"><a href="netsource.php" class="nav-link">馆藏查询</a></li>
      <li class="nav-item"><a href="serveInstruction_1.html" class="nav-link">服务指南</a></li>
      <li class="nav-item"><a href="user.html" class="nav-link">个人中心</a></li>
    </ul>
  </div>
  <form class="search" action="netsource.php" method="post" id="myform">
    <input type="text" class="form-control" name="bookname2" id="ser_input" placeholder="搜索书名、类型、序列号"/>
    <input type="image" src="image/search.png" style="width: 25px" class="img_ser" onClick="document.getElementById('myform').submit()" name="submit">
  </form>
  <div class="identity">
    <ul class="nav justify-content-center">
      <li class="nav-item"><img src="image/user.png" style="width: 50px ;" class="img_user" /></li>
      <li class="nav-item"><a href="login.html" class="nav-link">登录</a></li>
      <li class="nav-item"><a href="register.html" class="nav-link">注册</a></li>
    </ul>
  </div>
</nav>
	
	<br>
	<br>

	<div class="container my-container" style="width:500px">
	  <h2 class="text-center">注册</h2>
	  <form onSubmit="return check()" action="" method="post" name="info" >
		<div class="form-group">
		  <label for="">用户名</label>
		  <input type="text" class="form-control" placeholder="请输入用户名" name="username" required="required" onChange="check_usr()">
		  用户名长度6-16位字母数字下划线组合，第一位必须为字母
		  <div id="usr" class="alert alert-danger alert-dismissable fade show" style="display:none">用户名格式错误!</div>
		</div>
		<div class="form-group">
		  <label for="">密码</label>
		  <input type="password" class="form-control" placeholder="请输入密码" name="password" required="required" onChange="check_pwd()">
		  密码长度6-16位字母数字下划线
		  <div id="pwd" class="alert alert-danger alert-dismissable fade show" style="display:none">密码格式不正确！</div>
		</div>
		<div class="form-group">
		  <label for="">再次输入密码</label>
		  <input type="password" class="form-control" placeholder="请再次输入密码" name="password_again" required="required" onChange="check_same()">
		  <div id="not_same"  class="alert alert-danger alert-dismissable fade show" style="display:none" >两次输入不一致 </div>
		</div>
		<div class="form-group">
		  <label for="">QQ</label>
		  <input type="text" class="form-control" placeholder="请输入QQ" name="qqnum" required="required" onChange="check_qq()">
		  <div id="qq"class="alert alert-danger alert-dismissable fade show" style="display:none">QQ格式不正确</div>
		</div>
		<div class="form-group">
		  <label for="">姓名</label>
		  <input type="text" class="form-control" placeholder="请输入姓名" name="name" required="required" >
		</div>
		<center>
		  <button type="submit" name="submit" class="btn btn-info">注册</button>
		</center>
	  </form>

	</div>

<!--   具体的php连接数据库效果请转至  http://www.jimmyking.cn:8080/ 查看  -->
<?php
if(isset($_POST["submit"]))
{
	$usr=$_POST["username"];
	$pwd=$_POST["password"];
	$qq=$_POST["qqnum"];
	$name=$_POST["name"];
	
	$servername1 = "localhost";
	$username1 = "query";
	$password1 = "1234";
	$dbname1="test";
	$conn = new mysqli($servername1, $username1, $password1,$dbname1);
	$sql="insert into user values('$usr','$pwd',$qq,'$name');";
	$qry="select * from user where username = '$usr';";
	$qryresult=$conn->query($qry);
	if($qryresult->num_rows<=0)
	{
		$conn->query($sql);
		$conn->close();
?>
<script>		
		alert ("注册成功！<?php echo $name; ?>");
		window.location.href="index.html";
		</script>
<?php
	}
	else
	{
		$conn->close();
?>
<script>
		alert ("用户名已存在！");
		</script>
<?php
	}
}
?>

</body>
</html>
